package mwt.xml.xdbforms.schemalayer.types;

import javax.xml.XMLConstants;
import mwt.xml.xdbforms.dblayer.metadata.impl.ColumnMetaData;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;


// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.78E3A251-92CC-947F-BEDD-303E31944AF2]
// </editor-fold> 
public class XmlSmallInt extends XmlInteger {

    public XmlSmallInt(Document doc) {
        super(doc);
    }

    XmlSmallInt() {
        
    }

    private void buildFragment(ColumnMetaData cmd) {


        Element xtype, restriction, maxInclusive, minInclusive;

        typeName = cmd.getTypeName();

        fragment = doc.createDocumentFragment();

        xtype = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:simpleType");
        xtype.setAttribute("name", typeName);
        cmd.setXschemaTypeName(typeName);
        restriction = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:restriction");
        restriction.setAttribute("base", "xs:integer");
        maxInclusive = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:maxInclusive");
        minInclusive = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:minInclusive");
        maxInclusive.setAttribute("value", Short.toString(Short.MAX_VALUE));
        minInclusive.setAttribute("value", Short.toString(Short.MIN_VALUE));
        restriction.appendChild(maxInclusive);
        restriction.appendChild(minInclusive);
        xtype.appendChild(restriction);
        fragment.appendChild(xtype);
        

        


    }

    @Override
    public DocumentFragment getSchemaType(ColumnMetaData cmd) {

        buildFragment(cmd);
        return fragment;



    }

    @Override
    public Object getXSchemaToJavaType(String baseType, String value) {
        Integer i = Integer.parseInt(value);
        return i;
    }


}

